package com.swagger.doc.swaggertodoc.controller;

import com.swagger.doc.swaggertodoc.dto.Table;
import com.swagger.doc.swaggertodoc.util.WordUtil;
import com.word.service.WordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
public class WordController {

    @Autowired
    private WordService tableService;

    @RequestMapping("/getHtml")
    public String getJson(Model model) {
        List<Table> list = tableService.tableList();
        model.addAttribute("table", list);
        return "word";
    }


    /***
     * 导出Word材质单
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "downloadWord", method = RequestMethod.GET)
    @ResponseBody
    public void exportMillCertificate(HttpServletRequest request,
                                      HttpServletResponse response) throws Exception {
        //获得数据，系统相关，就不展示了
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("table", tableService.tableList());

        WordUtil.exportMillCertificateWord(request, response, map, "ceshi");
    }


}
